<template>
  <div class="app-container">
    <div class="app-container_conter">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px" style="display: flex;justify-content: space-between;align-items: flex-end">
      <div>
      <el-form-item label="操作类型" prop="operType">
        <el-select v-model="queryParams.operType" placeholder="请选择操作类型" clearable size="small">
          <el-option
            v-for="dict in operTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="操作人" prop="operName">
        <el-input
          v-model="queryParams.operName"
          placeholder="请输入操作人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      </div>
      <div style="width: 150px">
      <el-form-item style="width: 150px;text-align: right">
        <el-button type="primary"  size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="info" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      </div>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="info"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['insurance:reportLog:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          size="mini"
          @click="handleExport"
          v-hasPermi="['insurance:reportLog:export']"
        >导出</el-button>
      </el-col>
<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" ></right-toolbar>-->
    </el-row>
    <el-table v-loading="loading" :data="reportLogList" @selection-change="handleSelectionChange" :header-cell-style="tableHeaderColor">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="数据编号" align="center" prop="id" fixed min-width="100px"/>
      <el-table-column label="姓名" align="center" prop="name" min-width="100px" />
      <el-table-column label="证件号码" align="center" prop="id_card_no" min-width="180px"/>
      <el-table-column label="操作人" align="center" prop="oper_name" min-width="100px"/>
      <el-table-column label="操作类型" align="center" prop="oper_type" :formatter="operTypeFormat" min-width="100px"/>
      <el-table-column label="内容" align="center" prop="contant" min-width="400px"/>
      <el-table-column label="创建时间" align="center" prop="create_time"  min-width="150px"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" min-width="100px">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['insurance:reportLog:edit']"-->
<!--          >修改</el-button>-->
          <el-button
              style="color:#FF0000"
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['insurance:reportLog:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>
    <pagination
        style="background: transparent"
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改报案日志对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="状态" prop="reportId">
          <el-input v-model="form.reportId" placeholder="请输入状态" />
        </el-form-item>
        <el-form-item label="操作类型" prop="operType">
          <el-select v-model="form.operType" placeholder="请选择操作类型">
            <el-option
              v-for="dict in operTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="内容" prop="contant">
          <el-input v-model="form.contant" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="操作人" prop="operName">
          <el-input v-model="form.operName" placeholder="请输入操作人" />
        </el-form-item>
<!--        <el-form-item label="状态">-->
<!--          <el-radio-group v-model="form.status">-->
<!--            <el-radio-->
<!--              v-for="dict in statusOptions"-->
<!--              :key="dict.dictValue"-->
<!--              :label="dict.dictValue"-->
<!--            >{{dict.dictLabel}}</el-radio>-->
<!--          </el-radio-group>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button type="info" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listReportLog, getReportLog, delReportLog, addReportLog, updateReportLog, exportReportLog,listReportLog1 } from "@/api/insurance/reportLog";

export default {
  name: "ReportLog",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报案日志表格数据
      reportLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 操作类型字典
      operTypeOptions: [],
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 状态字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        user_id:'',
        pageNum: 1,
        pageSize: 10,
        reportId: null,
        operType: null,//操作类型
        contant: null,
        operName: null,//操作人
        createTime: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.queryParams.user_id = JSON.parse(localStorage.getItem('userInfo')).userId;
    this.getList();
    this.getDicts("sys_oper_type").then(response => {
      this.operTypeOptions = response.data;
    });
    this.getDicts("sys_common_status").then(response => {
      this.statusOptions = response.data;
    });
  },
  methods: {
    /* 修改表头颜色 */
    tableHeaderColor({ rowIndex }) {
      if (rowIndex === 0) {
        return 'background-color: #304156;color: #fff;font-weight: 400;font-family: Microsoft YaHei;'
      }
    },
    /** 查询报案日志列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];

      }
      // console.log('queryParams',this.queryParams)
      listReportLog(this.queryParams).then(res=>{
        // console.log('报案日志',res)
      })
      listReportLog1(this.queryParams).then(response => {
        // console.log('报案日志12',response)
        this.reportLogList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 操作类型字典翻译
    operTypeFormat(row, column) {
      return this.selectDictLabel(this.operTypeOptions, row.oper_type);
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        reportId: null,
        operType: null,
        contant: null,
        operName: null,
        createTime: null,
        updateTime: null,
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报案日志";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getReportLog(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报案日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateReportLog(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReportLog(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除报案日志编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delReportLog(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      var that=this;
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有报案日志数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
        const loading = that.$loading({
          lock: true,
          text: '请耐心等待正在导出数据...',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
           exportReportLog(queryParams).then(response=>{
             loading.close();
             that.$message({
               message: '导出数据成功!',
               type: 'success'
             });
             that.download(response.msg);
           });
        }).then(response => {

        })
    }
  }
};
</script>

